package com.lk.mall.service.impl;

import com.lk.mall.common.IndexConfigTypeEnum;
import com.lk.mall.common.SystemConstant;
import com.lk.mall.mapper.IndexConfigMapper;
import com.lk.mall.model.entity.Carousel;
import com.lk.mall.model.entity.GoodsInfo;
import com.lk.mall.model.entity.IndexConfig;
import com.lk.mall.model.vo.IndexInfoVo;
import com.lk.mall.model.vo.MallCarouselVo;
import com.lk.mall.model.vo.MallIndexConfigGoodsVo;
import com.lk.mall.service.ICarouselService;
import com.lk.mall.service.IGoodsInfoService;
import com.lk.mall.service.IIndexConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lk.mall.util.BeanUtil;
import com.lk.mall.util.PageQueryUtil;
import com.lk.mall.util.PageResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lak
 * @since 2022-08-31
 */
@Service
public class IndexConfigServiceImpl extends ServiceImpl<IndexConfigMapper, IndexConfig> implements IIndexConfigService {
    @Resource
    private IndexConfigMapper indexConfigMapper;

    @Autowired
    private IGoodsInfoService goodsInfoService;

    @Override
    public PageResult<IndexConfig> getConfigsPage(PageQueryUtil pageQueryUtil) {
        return null;
    }

    //获取首页商品信息
    @Override
    public List<MallIndexConfigGoodsVo> getIndexGoods(int type, int number) {
        List<IndexConfig> configGoodList = indexConfigMapper.getConfigGoods(type, number);
        List<GoodsInfo> goodsInfoList=new ArrayList<>();
        for (IndexConfig configGood : configGoodList) {
            GoodsInfo goodsInfo=goodsInfoService.getGoodInfoById(configGood.getGoodsId());
            String goodsIntro;
            if (goodsInfo.getGoodsIntro().length() > 22) {
                goodsIntro=goodsInfo.getGoodsIntro().substring(0,22)+"......";
                goodsInfo.setGoodsIntro(goodsIntro);
            }
            goodsInfoList.add(goodsInfo);
        }

        List<MallIndexConfigGoodsVo> goodsVoList=BeanUtil.copyList(goodsInfoList,MallIndexConfigGoodsVo.class);
        return goodsVoList;
    }
}
